#pragma once
#include "../buffer.h"
#include <mutex>
#include "../thread.h"
#include <memory.h>

#include <fstream>
#include <unistd.h>
namespace TinyRPC{

//LogStream 负责将 将buffer内容 输出到文件中
class LogStream{

public:
    LogStream(std::ofstream& ofs);
    void log(const std::string& str);
    ~LogStream();
private:
    void loggingThreadFunc();
private:
    Buffer * m_currentBuffer;
    Buffer * m_nextBuffer;
    std::mutex m_mutex;
    std::unique_ptr<Thread> m_loggingThread;
    std::ofstream& m_ofstream;
    bool m_quit;
};
}